﻿using Freebase4net.Interfaces;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Freebase4net.Operators.Bases
{
    public class MultiOperator : IOperator
    {
        private IOperator[] _operators;
        public MultiOperator(params IOperator[] operators)
        {
            _operators = operators;
        }


        public object Value
        {
            get { return _operators; }
        }

        public string CreateJson(string key)
        {
            StringBuilder builder = new StringBuilder();
            var last = _operators.Last();
            foreach (var op in _operators)
            {
                builder.Append(op.CreateJson(key));
                if (last != op)
                {
                    builder.Append(",");
                    builder.AppendLine();
                }
            }

            return builder.ToString();
        }


        public bool IncludeKeyWithNull
        {
            get { return true; }
        }
    }
}
